package com.crk.shixiguanli.controller;

import com.crk.shixiguanli.entity.Plan;
import com.crk.shixiguanli.entity.Task;
import com.crk.shixiguanli.service.PlanService;
import com.crk.shixiguanli.service.TaskService;
import com.crk.shixiguanli.util.LayUiTableJson;
import com.crk.shixiguanli.util.Page;
import com.crk.shixiguanli.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author
 * @description:
 * @date 2020/4/27
 */
@RestController
@RequestMapping("task")
public class TaskController {
    @Autowired
    TaskService taskService;

    /**
     * 列表页
     * @return
     */
    @RequestMapping("manage")
    public ModelAndView manage(){
        ModelAndView modelAndView = new ModelAndView("/workspace/task/taskList.html");
        return modelAndView;
    }

    /**
     * 详情页
     * @return
     */
    @GetMapping("detail")
    public ModelAndView detail(){
        ModelAndView modelAndView = new ModelAndView("/workspace/task/taskAdd.html");
        return modelAndView;
    }


    @RequestMapping("myTask")
    public ModelAndView myTask(){
        ModelAndView modelAndView = new ModelAndView("/workspace/task/myTask.html");
        return modelAndView;
    }

    @RequestMapping("myTaskShow")
    public ModelAndView myTaskShow(){
        ModelAndView modelAndView = new ModelAndView("/workspace/task/myTaskShow.html");
        return modelAndView;
    }


    @RequestMapping("taskComplete")
    public ModelAndView taskComplete(){
        ModelAndView modelAndView = new ModelAndView("/workspace/task/taskComplete.html");
        return modelAndView;
    }

    @RequestMapping("taskCompleteShow")
    public ModelAndView taskCompleteShow(){
        ModelAndView modelAndView = new ModelAndView("/workspace/task/taskCompleteShow.html");
        return modelAndView;
    }





    /**
     * 分页查询
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("queryPage")
    public LayUiTableJson queryPage(@RequestParam(defaultValue = "1") int page
            , @RequestParam(defaultValue = "10") int limit){
        Page pageInfo = new Page();
        pageInfo.setCurrentPage(page);
        pageInfo.setSize(limit);
        ResponseResult ResponseResult = taskService.queryPage(pageInfo);
        LayUiTableJson layUiTableJson = new LayUiTableJson(0,null,pageInfo.getAllRow(),(List)ResponseResult.getData());
        return layUiTableJson;
    }

    @GetMapping("getMyTask")
    public LayUiTableJson getMyTask(String status,@RequestParam(defaultValue = "1") int page
            , @RequestParam(defaultValue = "10") int limit){
        Page pageInfo = new Page();
        pageInfo.setCurrentPage(page);
        pageInfo.setSize(limit);
        ResponseResult ResponseResult = taskService.getMyTask(status,pageInfo);
        LayUiTableJson layUiTableJson = new LayUiTableJson(0,null,pageInfo.getAllRow(),(List)ResponseResult.getData());
        return layUiTableJson;
    }

    @GetMapping("queryTaskComplete")
    public LayUiTableJson queryTaskComplete(String taskName,String status,String studentName,@RequestParam(defaultValue = "1") int page
            , @RequestParam(defaultValue = "10") int limit){
        Page pageInfo = new Page();
        pageInfo.setCurrentPage(page);
        pageInfo.setSize(limit);
        ResponseResult ResponseResult = taskService.queryTaskComplete(taskName,status,studentName,pageInfo);
        LayUiTableJson layUiTableJson = new LayUiTableJson(0,null,pageInfo.getAllRow(),(List)ResponseResult.getData());
        return layUiTableJson;
    }

    /**
     * 查询所有
     * @return
     */
    @RequestMapping("queryAll")
    public ResponseResult queryAll(){
        return taskService.queryAll();
    }

    /**
     * 查询单个
     * @param id
     * @return
     */
    @RequestMapping("getOne")
    public ResponseResult getOne(@RequestParam("id") Integer id){
        return taskService.getOne(id);
    }

    @RequestMapping("getTaskComplete")
    public ResponseResult getTaskComplete(@RequestParam("id") Integer id){
        return taskService.getTaskComplete(id);
    }


    /**
     * 保存数据
     * @param task
     * @return
     */
    @RequestMapping("save")
    public ResponseResult save(Task task){
        return taskService.save(task);
    }

    /**
     * 删除数据
     * @param id
     * @return
     */
    @RequestMapping("delete")
    public ResponseResult delete(@RequestParam("id") Integer id){
        return taskService.delete(id);
    }


    @PostMapping("completeTask")
    public ResponseResult completeTask(@RequestParam("id") Integer id,@RequestParam("completeDesc") String completeDesc){
        return taskService.completeTask(id,completeDesc);
    }

    @RequestMapping("evaluate")
    public ResponseResult evaluate(@RequestParam("id") Integer id,@RequestParam("evaluate") String evaluate,@RequestParam("score") String score){
        return taskService.evaluate(id,evaluate,score);
    }

}
